import { isPromise } from 'util/types';

export const DefaultPageSize: number = 20;
export const DefaultPageNo: number = 1;

export class CommonPageDto {
  column: string;
  order: string;
  pageNo: number;
  pageSize: number;
}

// export function renderCommonPageResult(list) {
//   return {
//     code: 0,
//     message: '',
//     result: {
//       records: list[0],
//       total: list[1],
//     },
//     success: true,
//     timestamp: Date.now(),
//   };
// }

export function renderCommonResult(o) {
  if (isPromise(o)) {
    return o.then(renderCommonResult);
  }
  return {
    code: 0,
    message: '',
    result: o,
    success: true,
    timestamp: Date.now(),
  };
}
